package com.cbd.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cbd.dao.ComplaintrecordDao;
import com.cbd.dao.PersonalcarportDao;
import com.cbd.dao.PurposeDao;
import com.cbd.dao.RentInfoDao;
import com.cbd.dao.RenterDao;
import com.cbd.pojo.Complaintrecord;
import com.cbd.pojo.Purpose;
import com.cbd.pojo.RentInfo;
import com.cbd.pojo.Renter;
import com.cbd.pojo.ShowRenter;
import com.cbd.service.RenterService;
import com.cbd.util.IQuantity;
@Service
public class RenterServiceImpl implements RenterService {
	@Resource(name="renterDaoImpl")
	private RenterDao renterDao;
	@Resource(name="complaintrecordDaoImpl")
	private ComplaintrecordDao complaintrecordDao;
	@Resource(name="personalcarportDaoImpl")
	private PersonalcarportDao carportDao;
	@Resource(name="rentInfoDaoImpl")
	private RentInfoDao rentInfoDao;
	@Resource(name="purposeDaoImpl")
	private PurposeDao purposeDao;
	@Override
	public int regist(Renter renter) {
		// TODO Auto-generated method stub
		renter.setRenterTime(new Date());
		return renterDao.regist(renter);
	}
	@Override
	public Renter findRenterByUserID(int userID) {
		// TODO Auto-generated method stub
		return renterDao.findRenterByUserID(userID);
	}
	@Override
	public int updateRenterByRenter(Renter renter) {
		// TODO Auto-generated method stub
		return renterDao.updateRenterByRenter(renter);
	}
	@Override
	public List<Object[]> findAllRecordByUserID(int userID) {
		// TODO Auto-generated method stub
		return renterDao.findAllRecordByUserID(userID);
	}
	@Override
	public List<Object[]> findOnePageRecordByUserID(int userID, int pageSize, int currentPage) {
		// TODO Auto-generated method stub
		return renterDao.findOnePageRecordByUserID(userID, pageSize, currentPage);
	}

	@Override
	public List<ShowRenter> showRenter(int page) {
		// TODO Auto-generated method stub
		int count=renterDao.count();
		//List<ShowRenter> list=new ArrayList<>();
		List<ShowRenter>list=renterDao.showRenter((page-1)*IQuantity.pageSize);
		ShowRenter renter=new ShowRenter();
		int pageSize=count%IQuantity.pageSize==0?count/IQuantity.pageSize:(int)(count/IQuantity.pageSize)+1;
		renter.setCount(pageSize);
		list.add(renter);
		
		//System.out.println(list.get(6));
		return list;
	}

	@Override
	public Object[] findRecordByRecordID(int recordID) {
		// TODO Auto-generated method stub
		return renterDao.findRecordByRecordID(recordID);
	}
	@Override
	public int addComplaintrecord(Complaintrecord complaintrecord) {
		// TODO Auto-generated method stub
		return complaintrecordDao.addComplaintrecord(complaintrecord);
	}
	@Override
	public void updateRpById(int renterID) {
		// TODO Auto-generated method stub
		renterDao.updateRpById(renterID);
	}
	@Override
	public List<Object[]> findCarPortsByTimes(String startTime, String endTime,int userID) {
		// TODO Auto-generated method stub
		return carportDao.findCarPortsByTimes(startTime,endTime,userID);
	}
	@Override
	public RentInfo findRentInfoByRentInfoID(int rentInfoID) {
		// TODO Auto-generated method stub
		return rentInfoDao.findRentInfoById(rentInfoID);
	}
	@Override
	public int addPurpose(Purpose purpose) {
		// TODO Auto-generated method stub
		//设置增加的意向为  未成交
		purpose.setDeal(false);
		return purposeDao.addPurpose(purpose);
	}
	@Override
	public List<Object[]> findOnePageCarPortByTime(int currentPage, String startTime,
			String endTime ,int userID) {
		// TODO Auto-generated method stub
		int pageSize = IQuantity.pageSize;
		return carportDao.findOnePageCarPortByTime(pageSize, currentPage, startTime, endTime, userID);
	}
	@Override
	public int findRecordIDFromComplaintByRecordID(int recordID) {
		// TODO Auto-generated method stub
		Object theRecordID = complaintrecordDao.findRecordIDFromComplaintByRecordID(recordID);
		if(theRecordID != null){
			return 1;
		}
		return 0;
	}


}
